home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / DiscreteUniform.h < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  79 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23. #ifndef _DiscreteUniform_h
  24. #define _DiscreteUniform_h 1
  25. #pragma once
  26.  
  27. #include <Random.h>
  28.  
  29. //
  30. //    The interval [lo..hi)
  31. // 
  32.  
  33. class DiscreteUniform: public Random {
  34.     long pLow;
  35.     long pHigh;
  36.     double delta;
  37. public:
  38.     DiscreteUniform(long low, long high, RNG *gen);
  39.  
  40.     long low();
  41.     long low(long x);
  42.     long high();
  43.     long high(long x);
  44.  
  45.     virtual double operator()();
  46. };
  47.  
  48. //#ifdef __OPTIMIZE__
  49.  
  50. #include <stream.h>
  51.  
  52. inline DiscreteUniform::DiscreteUniform(long low, long high, RNG *gen) : (gen)
  53. {
  54.     pLow = (low < high) ? low : high;
  55.     pHigh = (low < high) ? high : low;
  56.     delta = (pHigh - pLow) + 1;
  57. }
  58.  
  59. inline long DiscreteUniform::low() { return pLow; }
  60.  
  61. inline long DiscreteUniform::low(long x) {
  62.   long tmp = pLow;
  63.   pLow = x;
  64.   delta = (pHigh - pLow) + 1;
  65.   return tmp;
  66. }
  67.  
  68. inline long DiscreteUniform::high() { return pHigh; }
  69.  
  70. inline long DiscreteUniform::high(long x) {
  71.   long tmp = pHigh;
  72.   pHigh = x;
  73.   delta = (pHigh - pLow) + 1;
  74.   return tmp;
  75. }
  76.  
  77. //#endif
  78. #endif
  79.